<template>
  <el-card class="box-card" style="margin: 10px 0px">
    <div slot="header" class="clearfix">
      <!-- tab栏 -->
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="销售额" name="销售额"></el-tab-pane>
        <el-tab-pane label="访问量" name="访问量"></el-tab-pane>
      </el-tabs>
      <!-- 右侧 -->
      <div class="right">
        <span @click="setDay">今日</span>
        <span @click="setWeek">本周</span>
        <span @click="setMonth">本月</span>
        <span @click="setYear">本年</span>
        <el-date-picker
          v-model="date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          class="date"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </div>
    </div>
    <!-- 中间 -->
    <div>
      <el-row :gutter="10">
        <!-- 中左 -->
        <el-col :span="18"><div ref="myChart" class="myChart"></div></el-col>
        <!-- 中右 -->
        <el-col :span="6">
          <div>
            <h5>门店{{ activeName }}排名</h5>
            <ul v-if="activeName==`销售额`">
              <li>
                <span class="ranking">1</span>
                <span>肯德基</span>
                <span class="value">323,234</span>
              </li>
              <li>
                <span class="ranking">2</span>
                <span>麦当劳</span>
                <span class="value">299,132</span>
              </li>
              <li>
                <span class="ranking">3</span>
                <span>海底捞</span>
                <span class="value">266,223</span>
              </li>
              <li>
                <span>4</span>
                <span class="store">西贝筱面村</span>
                <span class="value">223,452</span>
              </li>
              <li>
                <span>5</span>
                <span class="store">汉堡王</span>
                <span class="value">219,663</span>
              </li>
              <li>
                <span>6</span>
                <span class="store">真功夫</span>
                <span class="value">200,997</span>
              </li>
              <li>
                <span>7</span>
                <span class="store">乡村基</span>
                <span class="value">186,329</span>
              </li>
            </ul>
            <ul v-else>
              <li>
                <span class="ranking">1</span>
                <span>麦当劳</span>
                <span class="value">211,335</span>
              </li>
              <li>
                <span class="ranking">2</span>
                <span>肯德基</span>
                <span class="value">210,597</span>
              </li>
              <li>
                <span class="ranking">3</span>
                <span>必胜客</span>
                <span class="value">200,998</span>
              </li>
              <li>
                <span>4</span>
                <span class="store">海底捞</span>
                <span class="value">199,220</span>
              </li>
              <li>
                <span>5</span>
                <span class="store">西贝筱面村</span>
                <span class="value">195,444</span>
              </li>
              <li>
                <span>6</span>
                <span class="store">汉堡王</span>
                <span class="value">180,161</span>
              </li>
              <li>
                <span>7</span>
                <span class="store">真功夫</span>
                <span class="value">172,995</span>
              </li>
            </ul>
          </div>
        </el-col>
      </el-row>
    </div>
  </el-card>
</template>

<script>
import * as echarts from "echarts";
import dayjs from "dayjs";
// import { mapState } from "vuex";
export default {
  mounted() {
    this.myChart = echarts.init(this.$refs.myChart);
    this.myChart.setOption({
      title: {
        text: "销售额趋势",
      },
      //提示
      tooltip: {
        trigger: "axis",
        axisPointer: {
          type: "shadow",
        },
      },
      grid: {
        left: "3%",
        right: "4%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: [
        {
          type: "category",
          data: [
            "1月",
            "2月",
            "3月",
            "4月",
            "5月",
            "6月",
            "7月",
            "8月",
            "9月",
            "10月",
            "11月",
            "12月",
          ],
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: "value",
        },
      ],
      series: [
        {
          name: "Direct",
          type: "bar",
          barWidth: "60%",
          data: [110, 120, 90, 220, 175, 212, 192, 95, 88, 120, 250, 310],
        },
      ],
    });
  },
  data() {
    return {
      activeName: "销售额",
      myChart: null,
      date: [],
    };
  },
  methods: {
    //点击tab
    handleClick(tab, event) {
      this.myChart.setOption({
        title: {
          text: `${tab.label}趋势`,
        },
        series: {
          data:tab.label=='销售额'?[110, 120, 90, 220, 175, 212, 192, 95, 88, 120, 250, 310]:[410, 82, 200, 334, 390, 330, 220, 150, 82, 200, 134, 290]
        },
      });
    },
    setDay() {
      const day = dayjs().format("YYYY-MM-DD");
      this.date = [day, day];
    },
    setWeek() {
      const start = dayjs().day(1).format("YYYY-MM-DD");
      const end = dayjs().day(7).format("YYYY-MM-DD");
      this.date = [start, end];
    },
    setMonth() {
      const start = dayjs().startOf("month").format("YYYY-MM-DD");
      const end = dayjs().endOf("month").format("YYYY-MM-DD");
      this.date = [start, end];
    },
    setYear() {
      const start = dayjs().startOf("year").format("YYYY-MM-DD");
      const end = dayjs().endOf("year").format("YYYY-MM-DD");
      this.date = [start, end];
    },
  },
  // computed: {
  //   ...mapState({
  //     Data: (state) => state.home.list,
  //   }),
  // },
  // 监视DATA,让组件挂载显示echart
  // watch: {
  //   Data() {
  //     this.myChart.setOption({
  //       series: {
  //         data: this.Data.orderFullYear,
  //       },
  //     });
  //   },
  // },
};
</script>

<style scoped>
.clearfix {
  display: flex;
  justify-content: space-between;
  position: relative;
}
.right {
  position: absolute;
  right: 0;
}
.date {
  width: 300px;
  margin: 0 20px;
}
.right span {
  margin: 0 10px;
}
ul {
  list-style: none;
  width: 100%;
  height: 300px;
  padding: 0px;
}
ul li {
  height: 12%;
}
.el-col {
  height: 300px;
}
.ranking {
  float: left;
  width: 20px;
  height: 20px;
  background: black;
  border-radius: 50%;
  color: white;
  text-align: center;
  margin-right: 60px;
}
.store {
  margin-left: 71px;
}
.value {
  float: right;
}
.myChart {
  width: 100%;
  height: 300px;
}
</style>